/**
 * @addtogroup FXMATH
 * @{
 */

/**
 * @file
 * @brief Graphics mathematics utilities
 */

#ifndef _FXMATH_GRPAHICS_
#define _FXMATH_GRPAHICS_

//*****************************************************************************
//* Convert polygon to Bezier curves
//*****************************************************************************
/**
 * @name Polygon to Bezier
 */
/*@{*/

/**
 * @brief	Smooth the source polygon into the destination one.
 *
 * @param[in]src		the source polygon.
 * @param[out]dst		the destination polygon.
 */
void	FX_Polygon_Smooth(const CFX_PointsF &src, CFX_PointsF &dst);

/**
 * @brief	Calculate control points between two vertice.
 *
 * @param[out]cp		two-elements point field to save control points.
 * @param[in]vertice	four-elements point field, vertice[0] is previous vertex, vertice[3] is next vertex,
 *						cp[0] & cp[1] are between vertice[1] and vertice[2].
 * @param[in]k			fraction to determine smoothness of Bezier curves. Default value is 0.5f, should be between 0.0f - 1.0f.
 */
void	FX_PolygonToBezier_CalcControlPoints(CFX_PointF cp[2], const CFX_PointF vertice[4], FX_FLOAT k = 0.5f);
/**
 * @brief	Convert a polygon(path) to Bezier curve.
 *
 * @param[out]bezierCurves	save Bezier curve data, the first four-points are the first Bezier curve,
 *							and the next three-points are the next phase.
 * @param[in]path			source polygon, if it's a close path, the first vertex should be same as the last one.
 * @param[in]k				fraction to determine smoothness of Bezier curves. Default value is 0.5f, should be between 0.0f - 1.0f.
 */
void	FX_PolygonToBezier_ConvertPath(CFX_PointsF &bezierCurves, const CFX_PointsF &path, FX_FLOAT k = 0.5f);

/*@}*/

//*****************************************************************************
//* Convert arc to bezier curves
//*****************************************************************************
/**
 * @name Arc to Bezier
 */
/*@{*/

/**
 * @brief	Convert an ellipse arc segment to a Bezier curve.
 *
 * @param[in]rect		ellipse rectangle.
 * @param[in]fStart		start angle in radian.
 * @param[in]fSweep		sweep angle in radian, should be between -PI/2 ~ PI/2, negative value is counterclockwise.
 * @param[out]bzPoints	save point array of bezier curve.
 *
 * @return	1 if fSweep is zero, or 4.
 */
FX_INT32	FX_ArcToBezier_Segment(const CFX_RectF &rect, FX_FLOAT fStart, FX_FLOAT fSweep, CFX_PointF bzPoints[4]);

/**
 * @brief	Convert an ellipse arc to Bezier curves.
 *
 * @param[in]rect		ellipse rectangle.
 * @param[in]fStart		start angle in radian.
 * @param[in]fSweep		sweep angle in radian, negative is counterclockwise. 
 * @param[out]points	save point array of bezier curves.
 *
 * @return	Count of returned points.
 *			If return value < 2, it's no meaning;
 *			If return value == 2, means a line from starting point to ending point;
 *			If return value > 2, the first four-points is a full part of bezier curve,
 *			and the next three-points is another bezier curve, and so on.
 */
FX_INT32	FX_ArcToBezier(CFX_RectF rect, FX_FLOAT fStart, FX_FLOAT fSweep, CFX_PointsF &points);

/**
 * @brief	Convert any arc to Bezier curves.
 *
 * @param[in]x1			X coordinate of starting point.
 * @param[in]y1			Y coordinate of starting point.
 * @param[in]x2			X coordinate of ending point.
 * @param[in]y2			Y coordinate of ending point.
 * @param[in]rx			radius of X axis.
 * @param[in]ry			radius of Y axis.
 * @param[in]angle		slope angle between the current coordinate X axis and arc X axis, in degree.
 * @param[in]bLargeArc	if it's TRUE, the arc span is greater than 180 degrees, or use small spanning arc.
 * @param[in]bSweep		if it's TRUE, draw arc in clockwise; or draw arc in anti-clockwise.
 * @param[out]points	save point array of bezier curves.
 *
 * @return	Count of returned points.
 *			If return value < 2, it's no meaning;
 *			If return value == 2, means a line from starting point to ending point;
 *			If return value > 2, the first four-points is a bezier curve, and the next three-points is another bezier curve, and so on.
 */
FX_INT32	FX_ArcToBezier(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2, FX_FLOAT rx, FX_FLOAT ry, FX_FLOAT angle, FX_BOOL bLargeArc, FX_BOOL bSweep, CFX_PointsF &points);

FX_BOOL     FX_PathFlatten(const CFX_GraphStateData& stateData, const CFX_PathData& path, CFX_PathData& outline);



/*@}*/

#endif //_FXMATH_GRPAHICS_

/** @} */
